<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>权限管理</title>
	<!--[if IE]>
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<![endif]-->
	<!-- Main Stylesheet --> 
	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css" type="text/css" />
	<!-- Your Custom Stylesheet --> 
	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/custom.css" type="text/css" />
	<link href="<%=request.getContextPath()%>/lib/thickbox/thickbox.css" rel="stylesheet" type="text/css" />
	<link href="<%=request.getContextPath()%>/lib/jquery/jquery.autocomplete.css" type="text/css" rel="stylesheet"/>
	<%@include file="/include/header.jsp" %>
	<style type="text/css">
		#show_area input[type="text"]{
			font-family:宋体;黑体;幼圆;楷体_GB2312;仿宋_GB2312;Arial,Helvetica,sans-serif;
			border:0px;width:100%;height:100;
		}
		.noborder {border:0px none; overflow:auto;}
	</style>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery-1.4.2.min.js"></script>
	<script src="<%=request.getContextPath()%>/js/administry.js"></script>
	<script src="<%=request.getContextPath()%>/lib/validator/formValidator_min.js"></script>
	<script src="<%=request.getContextPath()%>/lib/validator/formValidatorRegex.js"></script>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery.form.js"></script>
	<script src="<%=request.getContextPath()%>/lib/datepicker/WdatePicker.js"></script>
	<script src="<%=request.getContextPath()%>/lib/thickbox/thickbox.js"></script>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery.autocomplete.pack.js"></script>
	<script src="<%=request.getContextPath()%>/js/function.js"></script>
	<script src="<%=request.getContextPath()%>/js/page/pageRender.js"></script>
	<script type="text/javascript">
	function showAddAuthForm(){
		getById("addAuth").reset();
		showBox("#TB_inline?height=220&width=500&inlineId=edit_container", "增加权限");
	}
	window.onload = init;
	function init(){
		
		window["PAGEBAR"] = new PageRender({
			method: 'POST',
			url:'<%=request.getContextPath()%>/protected/system/listAuth.action',
			start: <s:property value="start"/>,
			limit: <s:property value="limit"/>,
			total: <s:property value="total"/>,
			data: {
				"authName" : "#s_authName",
				"orderby" : "#orderby",
				"locked" : "#locked",
				"type" : "#s_type"
			}
		});
		
		window["PAGEBAR"].render(getById("page_bar"));
		
	}
	function doSearch(){
		Mask.show();
		window["PAGEBAR"].position(1);
	}

	$(document).ready(function(){
		Administry.contextBoxInit();
		
		<sec:authorize ifAnyGranted="ADMIN,AUTH_ADD">
		$.formValidator.initConfig({
			formID:"addAuth",
			onError:function(msg){
				showTip(msg);
			},
			onSuccess:function(){
				if( confirm("准备提交数据，是否继续？") ){
					Mask.show();
					$('#addAuth').ajaxSubmit(function(rslt){Ajax.callback(rslt, function(){
						Mask.hide();
						tb_remove();
						doSearch();
					});});
				}
				return false;
			}
		});
		$("#code").formValidator({
			onShow:"请输入权限编码",
			onFocus:"2-30个字符"
		}).inputValidator({min:2,max:30});
		$("#name").formValidator({
			onShow:"请输入权限名",
			onFocus:"2-30个字符"
		}).inputValidator({min:2,max:30});
		$("#type").formValidator({
			onShow:"请输入权限类别，同类别的权限将显示为一组",
			onFocus:"2-30个字符",
			empty:true
		}).inputValidator({min:2,max:30});
		</sec:authorize>
		
		//AutoComplete权限名关键字输入框
		$("#s_authName").autocomplete(
		'<%=request.getContextPath()%>/protected/system/autoCompleteAuth.action',
		{
			width: 250,
			max: 10,
			scroll: true,
			scrollHeight: 300,
			dataType: 'json',
			matchCase:true,
			parse: function(data) {
				if(!isArray(data)){
					data = eval("("+data+")");
				}
				var rows = [];
				for(var i=0; i<data.length; i++){
					rows.push({
						"data" : data[i],
						"value" : data[i][1],
						"result" : this.formatResult && this.formatResult(data[i], data[i][1]) || data[i][1]
					});
				}
				return rows;
			},
			formatItem: function(data, i, total) {
				return data[0]+" | " + data[1];
			}
		});
	
		$("#s_type").autocomplete(
		'<%=request.getContextPath()%>/protected/system/autoCompleteTypeAuth.action',
		{width: 160,
			max: 10,
			scroll: true,
			scrollHeight: 300,
			dataType: 'json',
			matchCase:true,
			parse: function(data) {
				if(!isArray(data)){
					data = eval("("+data+")");
				}
				var rows = [];
				for(var i=0; i<data.length; i++){
					rows.push({
						"data" : data[i],
						"value" : data[i],
						"result" : this.formatResult && this.formatResult(data[i], data[i]) || data[i]
					});
				}
				return rows;
			},
			formatItem: function(data, i, total) {
				return data;
			}
		});
	});
	</script>
</head>
<body>
	<%@include file="/include/body.jsp" %>
	
<s:if test="flag">
	<!-- 显示操作成功 -->
	<script type="text/javascript">
		showTip("操作成功");
	</script>
</s:if>

<!-- Wrapper -->
<div class="wrapper">
	
    <div class="content-box resizable" id="query_area">
    	<header>
			<h3>搜索</h3>
		</header>
		<section>
		<table class="no-style">
			<tbody>
			<tr>
				<td>
		        	<span>权限名关键字:
		        		<input id="s_authName" type="text" name="s_authName" value="<s:property value="authName"/>" class="input input_wa" />
		        	</span>
		        	<span>类别关键字:
		        		<input id="s_type" type="text" name="s_type" value="<s:property value="type"/>" class="input input_wa" />
		        	</span>
			    	<span>锁定状态：
			    		<s:select id="locked" value="locked" theme="simple" list="#{'2':'全部','0':'未锁定','1':'锁定'}">
			   			</s:select>
			    	</span>
		        	<span>
						<button class="btn" type="submit" onclick="doSearch();"><span class="icon icon-search"></span>搜 索</button>
					</span>
				</td>
			</tr>
			</tbody>
		</table>
		</section>
	</div>
	<div class="content-box" id="show_area">
	<header>
		<h3>
			<span>权限列表</span>
	    	<span>排序：
		    	<s:select id="orderby" value="orderby" onchange="doSearch();" theme="simple" 
		   			list="#{'order by code':'权限编码','order by name':'权限名','order by type,code':'类型和编码','order by type,name':'类型和权限名'}">
		   		</s:select>
	    	</span>
	 	</h3>
    	<div>
    	 <sec:authorize ifAnyGranted="ADMIN,AUTH_ADD">
	    	<span>
	    		<span>
	    			<a class="btn btn-gray" href="javascript:void(0)" onclick="javascript:doSearch();"><span class="icon icon-refresh"></span>刷新</a>
	    		</span>
	    		<span>
	    			<a class="btn" href="javascript:void(0)" onclick="javascript:showAddAuthForm();"><span class="icon icon-add"></span>增加权限..</a>
	    		</span>
	    	</span>
	    </sec:authorize>
	    </div>
	 </header>
	 <section>
	  <table class="display stylized" id="data_table">
     	<thead>
		<tr>
			<th>序号</th><th>编码</th><th>权限名</th><th>类别</th>
			<th>描述</th><th>锁定状态</th><th>操作</th>
		</tr>
		</thead>
		<tbody>
		<s:if test="auths != null">
			<s:iterator value="auths" status="authstatus">
			<form id="form_<s:property value="code"/>" action="<s:url value='editAuth.action'></s:url>" method="post">
				<tr>
					<td><s:property value="#authstatus.index + 1+start"/></td>
					<td>
						<s:property value="code"/>
						<input type="hidden" name="auth.code" value="<s:property value="code"/>"/>
					</td>
			 		<td><input type="text" name="auth.name" value="<s:property value="name"/>"/></td>
			 		<td><input type="text" name="auth.type" value="<s:property value="type"/>"/></td>
			 		<td><input type="text" name="auth.desn" value="<s:property value="desn"/>"/></td>
			 		<td>
			 		<s:if test="#attr.SEC_ISADMIN">
			 		<input type="checkbox" name="auth.locked" value="true" <s:if test="locked">checked</s:if>/>
			 		</s:if>
			 		<s:else>
			 		<input type="hidden" name="auth.locked" value="<s:property value="locked"/>" />
			 		<s:if test="locked">已锁定</s:if><s:else>未锁定</s:else>
			 		</s:else>
			 		</td>
			 		<td>
			 		<s:if test="type != 'SYSTEM' || #attr.SEC_ISADMIN">
				 		<sec:authorize ifAnyGranted="ADMIN,AUTH_UPDATE">
				 			<a href="javascript:void(0);" onclick="if(confirm('请确认')){Mask.show();$('#form_<s:property value="code"/>').ajaxSubmit(Ajax.callback);}">［更新］</a>
				 		</sec:authorize>
				 		<s:if test="! locked">
				 		<sec:authorize ifAnyGranted="ADMIN,AUTH_DELETE">
				 			<a href="javascript:void(0);" onclick="if(confirm('是否删除权限?')){document.location.href='<s:url value='delAuth.action?id=%{code}'></s:url>';}">［删除］</a>
				 		</sec:authorize>
				 		</s:if>
			 		</s:if>
			 		</td>
			 	</tr>
			 	</form>
			</s:iterator>
		 </s:if>
		 </tbody>
	</table>
	<div id="page_bar"></div>
	</section>
	</div>
</div>

<div id="edit_container" style="display:none;">
 <div class="admin_table mb10" id="edit_area">
  <sec:authorize ifAnyGranted="ADMIN,AUTH_ADD">
	<s:form id="addAuth" action="addAuth.action" namespace="/protected/system" method="post" theme="simple">
	<table class="no-style">
		<tr>
			<td class="td1"><label class="required">编码</label></td>
			<td><input id="code" type="text" name="auth.code" value=""/></td>
			<td><div id="codeTip"></div></td>
		</tr>
		<tr>
			<td class="td1"><label class="required">权限名</label></td>
			<td><input id="name" type="text" name="auth.name" value=""/></td>
			<td><div id="nameTip"></div></td>
		</tr>
		<tr>
			<td class="td1"><label class="required">类别</label></td>
			<td><input id="type" type="text" name="auth.type" value=""/></td>
			<td><div id="typeTip"></div></td>
		</tr>
		<tr>
			<td class="td1"><label>描述</label></td>
			<td><input id="desn" type="text" name="auth.desn" value=""/></td>
			<td><div id="desnTip"></div></td>
		</tr>
		<s:if test="#attr.SEC_ISADMIN">
		<tr>
			<td class="td1"><label>锁定</label></td>
			<td><input id="locked" type="checkbox" name="auth.locked" value="true"/></td>
			<td></td>
		</tr>
		</s:if>
	</table>
	<div class="form-btn">
		<button class="btn btn-green" type="submit"><span class="icon icon-ok"></span>提 交</button>
		<button class="btn" type="reset" onclick="javascript:tb_remove();"><span class="icon icon-close"></span>取消</button>
	</div>
	</s:form>
</sec:authorize>
</div>
</div>
</body>
</html>